package com.example.lcode.greedy;

import java.util.LinkedList;

public class Question649 {

    public String predictPartyVictory(String senate) {
        LinkedList<Character> list = new LinkedList<>();
        for (int i = 0; i < senate.length(); i++) {
            list.add(senate.charAt(i));
        }
        char lastChar = 'A';
        int sign = 0;
        int personNumber = 0;
        while (list.size() != 0) {
            if (lastChar == 'A') {
                lastChar = list.peekFirst();
                list.addLast(list.pollFirst());
                personNumber ++;
            } else if (lastChar != list.peekFirst()) {
                personNumber --;
                if (personNumber == 0) {
                    lastChar = 'A';
                }
                sign = 0;
                list.pollFirst();
            } else {
                sign ++;
                personNumber ++;
                if (sign == list.size()){
                    if ('R' == list.peekFirst()) {
                        return "Radiant";
                    } else {
                        return "Dire";
                    }
                }
                list.addLast(list.pollFirst());
            }
        }
        return "Radiant";
    }

    public static void main(String[] args) {
        Question649 question649 = new Question649();
        String d = question649.predictPartyVictory("DDRRR");
        System.out.println(d);

    }

}
